package com.iqiyi.pps.epg.core.dao.auth;

import com.iqiyi.pps.epg.core.dao.base.HibernateDao;
import com.iqiyi.pps.epg.core.model.auth.Authority;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 权限操作Dao类
 */
@Component
public class AuthorityDao extends HibernateDao<Authority, Long> {

    /**
     * 通过权限的名称查询
     * @param name 权限的名称
     * @return Authority
     */
    public Authority getAuthorityByName(String name) {
        String HQL = "From Authority where name=?";
        List<Authority> result = createQuery(HQL, name).list();
        // 存在name相同的权限
        if(result.size() > 1){
            System.out.print("权限表中存在name相同的权限");
           // return result.get(0);
            return null;
        }
        return result.get(0);
     }

}
